//
//  MYGHealthManagementHeadView.swift
//  MYGrow
//
//  Created by 林矗 on 2024/3/9.
//

import UIKit
import QMUIKit
class MYGHealthManagementHeadView: UIView {
    // MARK: - Property
    var name: String = "" {
        didSet {
            nameLabel.text = name
        }
    }
    
    var headImageUrl: String = "" {
        didSet {
            headImageView.sd_setImage(with: URL(string: headImageUrl), placeholderImage: UIImage(named: "head"))
        }
    }
    
    var action: (() -> ())?
    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        addSubviews([
            bgImaVgeView,
            headImageView,
            nameLabel,
        ])
        
        bgImaVgeView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        headImageView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(navHeight+statusBarHeight+20)
            make.left.equalToSuperview().offset(15)
            make.size.equalTo(CGSize(width: 80, height: 80))
            make.bottom.equalToSuperview().offset(-50)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(headImageView.snp.right).offset(10)
            make.height.equalTo(29.5)
            make.centerY.equalTo(headImageView)
        }
        
    }
    
    // MARK: - Public funcs
    
    // MARK: - lazy load
    private lazy var bgImaVgeView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "MYG_health_bg"))
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        return imageV
    }()
    
    private lazy var headImageView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "head"))
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        imageV.layerCornerRadius = 40
        imageV.layerBorderWidth = 1
        imageV.layerBorderColor = .white
        return imageV
    }()
    
    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(21)
        label.textColor = .white
        label.text = "乔淑琴"
        return label
    }()
}

extension MYGHealthManagementHeadView {
    @objc func buttonEvent() {
        action?()
    }
}
